package com.fastCms.business.bim.manage.impl;

import java.util.List;

import com.fastCms.business.bim.daos.DataListenMapper;
import com.fastCms.business.bim.manage.DataListenManageService;
import com.fastCms.business.bim.pojo.entity.DataListen;
import com.fastCms.business.bim.pojo.vo.FactoryActualVO;
import com.fastCms.business.bim.pojo.vo.StandardDateListenVO;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor = Exception.class)
@Component
@Slf4j
public class DataListenManageServiceImpl implements DataListenManageService {

    @Autowired
    private DataListenMapper dataListenMapper;

    @Override
    public ApiResponse<FactoryActualVO> factoryActual() {
        //查找监测厂区环境的设备
        long deviceId = 100;
        List<DataListen> dataListen = dataListenMapper.getActualByDeviceId(deviceId);
        if (!dataListen.isEmpty()) {
            FactoryActualVO build = FactoryActualVO.builder()
                .aqi(dataListen.get(0).getAqi())
                .category("轻度")
                .pm10(dataListen.get(0).getPm10())
                .pm25(dataListen.get(0).getPm25())
                .primary("PM10")
                .build();

            return ResponseUtil.success(build);
        }
        return ResponseUtil.success(new FactoryActualVO());
    }

    @Override
    public ApiResponse<StandardDateListenVO> standard() {
        StandardDateListenVO build = StandardDateListenVO.builder().pm10Standard("25").pm25Standard("60").build();
        return ResponseUtil.success(build);
    }
}
